<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="用户" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="币种" prop="currency">-->
<!--        <el-select-->
<!--          v-model="queryParams.currency"-->
<!--          placeholder="角色状态"-->
<!--          clearable-->
<!--          size="small"-->
<!--          style="width: 240px"-->
<!--        >-->
<!--          <el-option-->
<!--            v-for="dict in currencyOptions"-->
<!--            :key="dict.dictValue"-->
<!--            :label="dict.dictLabel"-->
<!--            :value="dict.dictValue"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="交易状态" prop="status">-->
<!--        <el-select-->
<!--          v-model="queryParams.status"-->
<!--          placeholder="角色状态"-->
<!--          clearable-->
<!--          size="small"-->
<!--          style="width: 240px"-->
<!--        >-->
<!--          <el-option-->
<!--            v-for="dict in statusOptions"-->
<!--            :key="dict.dictValue"-->
<!--            :label="dict.dictLabel"-->
<!--            :value="dict.dictValue"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="时间区间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-row>
      <el-col>
        <el-table v-loading="loading" :data="roleList">
          <el-table-column label="交易id" prop="id"   v-if="columns[0].visible"/>
          <el-table-column label="用户名" prop="username"   v-if="columns[1].visible"/>
          <el-table-column label="钱包地址" prop="targetAccount" v-if="columns[2].visible"/>
          <el-table-column label="金额" prop="amount"  v-if="columns[3].visible"/>
          <el-table-column label="币种" prop="currency"  v-if="columns[4].visible"/>
          <el-table-column label="归集时间" align="center" prop="createTime"  v-if="columns[5].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { chargeList} from "@/api/biz";


export default {
  name: "Charge",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 日期范围
      dateRange: [],
      // 币种状态数据字典
      currencyOptions: [
        {
          dictValue:'BTC',
          dictLabel:'BTC'
        },
        {
          dictValue:'USDT',
          dictLabel:'USDT'
        }
      ],
      // 状态数据字典
      statusOptions: [
        {
          dictValue:'1',
          dictLabel:'待审核'
        },
        {
          dictValue:'2',
          dictLabel:'已成功'
        },
        {
          dictValue:'3',
          dictLabel:'已撤销'
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: undefined,
        currency: undefined,
        status: undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `交易id`, visible: true },
        { key: 1, label: `用户名`, visible: true },
        { key: 2, label: `钱包地址`, visible: true },
        { key: 3, label: `金额`, visible: true },
        { key: 4, label: `币种`, visible: true },
        { key: 5, label: `归集时间`, visible: true }
      ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      chargeList(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.roleList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
